import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Stock } from '../stock.service';
import { StockService } from '../stock.service';
import { FormControl } from '@angular/forms';
import 'rxjs/Rx';

@Component({
  selector: 'app-stock-management',
  templateUrl: './stock-management.component.html',
  styleUrls: ['./stock-management.component.css']
})
export class StockManagementComponent implements OnInit {
  //// 为什么写在这，而不写在constructor里
  private stocks: Array<Stock>
  nameFilter: FormControl = new FormControl();
  private keyWords: string
  constructor(public router: Router, private stockService: StockService ) {
  }

  ngOnInit() {
    this.stocks = this.stockService.getStocks();
    this.nameFilter.valueChanges.debounceTime(500).subscribe(value => (this.keyWords = value, console.log(value)));
  }
  createStock() {
    this.router.navigateByUrl('/stock/0');
  }
  updateStock(stock: Stock) {
    this.router.navigateByUrl('/stock/' + stock.id);
  }

}


